#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* oddEvenList(struct ListNode* head) {
    if (head == NULL || head->next == NULL || head->next->next == NULL)
        return head;
    struct ListNode* s_head = head, * s_tail = head;
    struct ListNode* d_head = head->next, * d_tail = head->next;
    while (d_tail && d_tail->next)
    {
        s_tail->next = d_tail->next;
        s_tail = s_tail->next;
        d_tail->next = s_tail->next;
        d_tail = d_tail->next;
    }
    s_tail->next = d_head;
    return s_head;
}